package data.objects;

import java.util.List;
import java.util.UUID;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIgnore;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;

import data.dynamodbfunctions.Persistence_Helper_Tenant;
import data.exceptions.Dynamo_DB_Functions_Exception;
import data.meta.Metadata;

@DynamoDBTable(tableName="CC_Tenant")
public class Tenant {
	public String Name;
	public String ID;
	public String TenantID;
	
	
		
	public Tenant(String tenantID, String name) {
		super();
		TenantID = tenantID;
		ID = ""+UUID.randomUUID();
		Name = name;
	}
	public Tenant() {
		ID = ""+UUID.randomUUID();
	}
	
	@DynamoDBHashKey(attributeName="ID")
	public String getTenantID() {return TenantID;}
	public void setTenantID(String tenantID) {TenantID = tenantID;}
	
	@DynamoDBRangeKey(attributeName="Range_ID")
	public String getID() {return ID;}
	public void setID(String iD) {ID = iD;}
	
	@DynamoDBAttribute(attributeName="Name")
	public String getName() {return Name;}
	public void setName(String name) {Name = name;}
	
	@DynamoDBIgnore
	public static Tenant create(String tenantID, String name) throws Dynamo_DB_Functions_Exception {
		Tenant object = new Tenant(tenantID, name);
		return Persistence_Helper_Tenant.getInstance().create(object);	
	}
	@DynamoDBIgnore
	public static Tenant read(String tenant_id, String id) throws Dynamo_DB_Functions_Exception {
		Tenant readobject=Persistence_Helper_Tenant.getInstance().read(tenant_id,id);
		return readobject;
	}
	@DynamoDBIgnore
	public static List<Tenant> read(String tenant_id) throws Dynamo_DB_Functions_Exception {
		List<Tenant> readobject=Persistence_Helper_Tenant.getInstance().readAllwithHashKey(tenant_id);
		return readobject;
	}
	
	@DynamoDBIgnore
	public static Tenant update(String tenant_id, String ID, String name) throws Dynamo_DB_Functions_Exception {
		Tenant updateFeature =Persistence_Helper_Tenant.getInstance().read(tenant_id,ID);
		if(!"".equals(name)){
			updateFeature.setName(name);
		}
		return Persistence_Helper_Tenant.getInstance().update(updateFeature);
	}
	
	@DynamoDBIgnore
	public static Tenant delete(String tenant_id, String id) throws Dynamo_DB_Functions_Exception {
		return Persistence_Helper_Tenant.getInstance().delete(tenant_id,id);
	}
	
	@DynamoDBIgnore
	public static Metadata getMetadata(){
		return ClassSpy.getMetadata("data.objects.Tenant");
	}
	
}
